package com.xc.utils;

import lombok.Data;

/**
 * 统一结果响应集resultful
 */
@Data
public class ResultVO<T> {
    private Integer code;
    private String msg;
    private T data;

    // 成功不带参数
    public static <T> ResultVO<T> success() {
        ResultVO<T> resultVO = new ResultVO<>();
        resultVO.setCode(200);
        resultVO.setMsg("成功");
        return resultVO;
    }

    //成功带参数
    public static <T> ResultVO<T> success(T data) {
        ResultVO<T> resultVO = new ResultVO<>();
        resultVO.setCode(200);
        resultVO.setMsg("成功");
        resultVO.setData(data);
        return resultVO;
    }

    // 错误
    public static <T> ResultVO<T> error(T data) {
        ResultVO<T> resultVO = new ResultVO<>();
        resultVO.setCode(0);
        resultVO.setMsg("失败");
        resultVO.setData(data);
        return resultVO;
    }

    // 错误，指定code
    public static <T> ResultVO<T> error(Integer code, T data) {
        ResultVO<T> resultVO = new ResultVO<>();
        resultVO.setCode(code);
        resultVO.setMsg("失败");
        resultVO.setData(data);
        return resultVO;
    }
}